package com.study.locks.jdk;

/**
 * 查看编译的（classes）原文件内容命令：
 * javap -c SellTicket_Sync

 * @author: chenhs
 * @date: Created in 6:47 2019/12/15
 **/
public class SellTicket_Sync implements Runnable {

    //100张票
    private int tickets = 100;

    @Override
    public void run() {
        while (tickets > 0) {

            synchronized (this) {
                if (tickets > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //窗口号
                    System.out.println(Thread.currentThread().getName() + "正在出票第 " + (tickets--) + " 张票");
                }
            }
        }
    }
}
